<?php

use yii\grid\GridView;
use common\helpers\Html;
use common\helpers\ImageHelper;
use common\enums\StatusEnum;
use kartik\select2\Select2;

$this->title = '订单管理';
$this->params['breadcrumbs'][] = $this->title;

/* @var $this \yii\web\View */
/* @var $dataProvider \yii\data\ActiveDataProvider */
/* @var $searchModel \common\models\base\SearchModel */






?>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title"><?= $this->title; ?></h3>
                <div class="box-tools">
                    <?= Html::create(['edit']) ?>
                </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body table-responsive">
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel' => $searchModel,
                    //重新定义分页样式
                    'tableOptions' => ['class' => 'table table-hover'],
                    'columns' => [
                        [
                            'class' => 'yii\grid\SerialColumn',
                            'visible' => false, // 不显示#
                        ],
                        'id',
                        'order_number',
                        'cate.member_name',
                        'addres.phone',
                        'ordercate.title',

                        [
                            'label' => '订单状态',
                            // 'filter' => false, //不显示搜索框
                            'value' => function ($model) {
                                return  Html::order_statu($model->order_statu);
                            },
                            'filter'=>Select2::widget(['name' =>'SearchModel[order_statu]',
                                'data' => $menuDropDownList,
                                'value' =>$searchModel->order_statu,
                                'options' => ['placeholder' => '请选择']
                            ]),
                            'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => '全部'],
                            'format' => 'raw',
                        ],
//                        [
//                            'attribute' => 'order_statu',
//                            'filter'=>Select2::widget(['name' =>'SearchModel[order_statu]',
//                                'data' => $menuDropDownList,
//                                'value' =>$searchModel->order_statu,
//                                'options' => ['placeholder' => '请选择']
//                            ]),
//                            'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => '全部'],
//                        ],
                        [
                            'label' => '上门时间',
                            'attribute' => 'order_visiting_time',
                            'filter' => false, //不显示搜索框
                            'format' => ['date', 'php:Y-m-d H:i:s'],
                        ],

                        [
                            'attribute'=>'img',
                            'format' => 'raw',
                            'value' => function($model){
                                return Html::img(explode(',',$model->img)[0],['class' => 'img-circle rf-img-md img-bordered-sm',]);
                            }
                        ],


//                        [
//                            'attribute' => 'img',
//                            'value' => function ($model) {
//                                return Html::img(ImageHelper::defaultHeaderPortrait(Html::encode($model->img)),
//                                    [
//                                        'class' => 'img-circle rf-img-md img-bordered-sm',
//                                    ]);
//                            },
//                            'filter' => false,
//                            'format' => 'raw',
//                        ],

                        //'type',
//                        [
//                            'label' => '类型',
//                            // 'filter' => false, //不显示搜索框
//                            'value' => function ($model) {
//                                if ($model->type == 1){
//                                    return  '平台新闻';
//                                }else{
//                                    return  '平台介绍';
//                                }
//
//                            },
//                            'format' => 'raw',
//                        ],
                       // 'content',
                        [
                            'label' => '描述',
                           // 'filter' => false, //不显示搜索框
                            'value' => function ($model) {
                                return  $model->order_describe;
                            },
                            'format' => 'raw',
                        ],
                        [
                            'label' => '创建时间',
                            'attribute' => 'created_at',
                            'filter' => false, //不显示搜索框
                            'format' => ['date', 'php:Y-m-d H:i:s'],
                        ],

                        [
                            'header' => "操作",
                            'class' => 'yii\grid\ActionColumn',
                            'template' => '{edit} {status} {delete}{type}{tyy}',
                            'buttons' => [
                                'status' => function ($url, $model, $key) {
                                    return Html::status($model->status);
                                },
                                'edit' => function ($url, $model, $key) {
                                    return Html::edit(['edit', 'id' => $model->id,'order_address'=>$model->order_address]);
                                },
                                'delete' => function ($url, $model, $key) {
                                    return Html::delete(['destroy', 'id' => $model->id]);
                                },
//                                'type'=>function($url, $model, $key){
//                                    return  Html::tyy(['type' => $model->type]);
//                                },
                                'type' => function ($url, $model, $key) {
                                    if($model->type == 2){
                                        return Html::linkButton(['donation/edit', 'id' => $model->id,'111'=>$model->type], '捐赠', [
                                            'data-toggle' => 'modal',
                                            'data-target' => '#ajaxModal',
                                         ]);
                                     }elseif ($model->type == 3){

                                        return Html::linkButton(['att', 'id' => $model->id], '已捐赠', [
                                            'data-toggle' => 'modal',
                                            'data-target' => '#ajaxModal',
                                        ]);
                                        //return '已捐赠';
                                    }

                                   },



                            ],
                        ],
                    ],
                ]); ?>

                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>
    </div>
</div>
<!--<div hidden>-->
<!--    <audio id ='hu' src="http://downsc.chinaz.net/Files/DownLoad/sound1/201202/634.mp3" controls></audio>-->
<!--    <button>ioioo</button>-->
<!--</div>-->
<!--<script>-->
<!--    var audio = document.getElementById('hu')-->
<!--    setTimeout(function () {-->
<!--        audio.play()-->
<!--    },5000)-->
<!--</script>-->
<!--<script>-->
<!---->
<!--    setInterval(audio,30000);//每59秒刷新查询一次-->
<!--    function audio() {-->
<!--        //var last_count = 4;-->
<!--        $.ajax({-->
<!--            type: "get",-->
<!--            url: "/api/v1/wxapp/qing",//后台方法-->
<!--            dataType: "json",-->
<!--            success: function(res) {-->
<!--               // alert(res.data);-->
<!--                if(res.data >0){-->
<!--                    var audio = document.getElementById('hu')-->
<!--                    setTimeout(function () {-->
<!--                        audio.play()-->
<!--                    },5000)-->
<!--                }-->
<!--            }-->
<!--        });-->
<!--    }-->
<!--</script>-->
